layui.use(['form', 'jquery'],function (){
    var form = layui.form;
    let $ = layui.jquery;
    var util = layui.util;

    submit();
    onFn();

    // 表单提交
    function submit(){
        form.on('submit(btn-submit)', function (data) {
            $.ajax({
                url: '/system/admin/save/',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (result) {
                    if (result.code === 0) {
                        layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); // 关闭当前页
                            parent.layui.table.reload("list", {
                                page: { curr: 1 },
                            });
                        });
                    } else {
                        parent.layer.msg('异常', { icon: 2 })
                    }
                }
            });

            return false;
        });
    }

    // 事件绑定
    function onFn(){
        util.on('lay-on', {
            // 关闭当前页
            'close': function () {
                window.parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        })
    }
});